﻿using System;
using System.Collections.Generic;
using BusinessLogic.Models.ValidationAttributes;
using Framework.Validation;
using Interfaces.Models;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace BusinessLogic.Models.LogicModels.Security
{
    
    public class User : IUser
    {
        [NotNullValidator(Tag = RulesKeys.Required)]
        public Guid Id { get; set; }

        [UserNameNotExistValidation(Message = "Login is already in use", 
            Tag = RulesKeys.UserNameNotExist, Ruleset = RulesetNames.Create)]
        [UserNameExistsValidation(Message = "Login not exists", 
            Tag = RulesKeys.UserNameExist, Ruleset = RulesetNames.Update)]
        [NotNullValidator(Tag = RulesKeys.Required, Ruleset = RulesetNames.Create)]
        public string UserName { get; set; }

        [NotNullValidator(Tag = RulesKeys.Required)]
        public string Password { get; set; }

        [EmailNotExistValidation(Message = "Email is already in use", 
            Tag = RulesKeys.EmailNotExist, Ruleset = RulesetNames.Create)]
        [EmailExistsValidation(Message = "Email not exists", Tag = RulesKeys.EmailExist, Ruleset = RulesetNames.Update)]
        [RegexValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*",
            Tag = RulesKeys.Format)]
        [NotNullValidator(Tag = RulesKeys.Required, Ruleset = RulesetNames.Create)]
        public string Email { get; set; }
        
        [ObjectCollectionValidator(typeof(IRole))]
        public ICollection<IRole> Roles { get; set; }
    }
}
